<?php
/**
 * @desc Benutzerverwaltung 
 */
class model_auth
{
	var $_loginstatus = false;

	//singleton
	private static $instance = null;
	//initialisierung nur über getInstance()
	protected function __construct(){}
	//kein Klonen
	private function __clone(){}

	public static function getInstance()
	{
		if(self::$instance == null)
		{
			self::$instance = new model_auth();
		}
		return self::$instance;
	}

	/**
	 * @Hilfsfunktion
	 */
	public function validate()
	{
		if(!isset($_POST['username']) or !isset($_POST['password']))
		{
			return false;
		}

		$userdata = config_system::getInstance()->convertConfig('auth','user');

		foreach($userdata as $user)
		{
			if($user['username'] == $_POST['username'] && $user['password'] == $_POST['password'])
			{
				return true;
			}
		}

		return false;
	}

	/**
	 * @desc gibt ein Array zum erstellen der Navigation abhängig vom Loginstatus
	 * @return array 
	 */
	public function getNavigationArray()
	{
		if($_SESSION['loginstatus'] == false)
		{
			$nav = array(array('href'=>'auth/index','name'=>'login'));
		}
		else
		{
			$nav = array(array('href'=>'auth/logout','name'=>'logout'));
		}

		return $nav;
	}
}